package cate.game.activity.dailylogin.paycallback;

import cate.common.table.d.GDFunc;
import cate.common.table.pay.PayItemRow;
import cate.common.util.GameResult;
import cate.game.GameBody;
import cate.game.activity.base.core.RoleActivitySingle;
import cate.game.activity.dailylogin.DailyLoginSingle;
import cate.game.pay.PayCallback;
import cate.game.pay.PayHandler;
import cate.game.role.Role;
import cp.solution.business.pay.PayRecordEntity;
import cp.solution.business.pay.dto.PayDeliverResult;
import easy.java.dev.note.NoteClass;

import java.util.Optional;

@NoteClass(value = "每日登陆活动支付回调")
@PayHandler(funcIds = {GDFunc.ACT_SEVEN_DAY_LOGIN, GDFunc.NATURE_SEVEN_DAY_LOGIN})
public class PayDailyLoginActivityCallback extends PayCallback {
    @Override
    public void onSuccess(GameBody game, Role role, PayRecordEntity record, PayDeliverResult result) {
        PayItemRow pir = game.table.pay.item.get(record.itemTid);
        if (pir == null) {
            return;
        }
        Optional.ofNullable((RoleActivitySingle) role.getActivity().getEnableActivitySingle(pir.funcId))
                .ifPresent(act -> act.onPaySuccess(pir));
    }

    @Override
    public void onFail(GameBody game, Role role, PayRecordEntity record, PayDeliverResult result) {

    }

    @Override
    public GameResult<Void> allowPay(Role role, PayItemRow pir) {
        DailyLoginSingle act = role.getActivity().getEnableActivitySingle(pir.funcId);
        if (act != null) {
            GameResult<Void> ecResult = act.allowPay(pir);
            if (ecResult != null) return ecResult;
        }
        return new GameResult<Void>().fail();
    }
}
